<?php

class Db_Tables_BjmBotsTo extends Zend_Db_Table
{
    protected $_name = 'bjm_bots_to';
	var $from_id;
	
	function GetToInfo()
	{
		$result = array();
		
		if($this->from_id)
		{
			$select = $this->select();
			$select->from($this->_name, array("bot_type", "group_id"));
			$select->where("from_id = ?", $this->from_id);
			$select->where("status = ?", 1);
			$select->where("expired_date >= ?", date("Y-m-d"));
			$rows = $this->fetchAll($select);
			
			if($rows)
			{
				foreach($rows as $row)
				{
					$result[] = array(
						'bot_type' => $row['bot_type'],
						'group_id' => $row['group_id']
					);
				}
			}
		}
		
		return $result;
	}
	
	function GetToInfoByFromGroupInfo($available_from_qq_groups)
	{
		$result = array();
		
		if(!empty($available_from_qq_groups))
		{
			$from_id_arr = array();
			
			foreach($available_from_qq_groups as $af)
			{
				$from_id_arr[] = $af['from_id'];
			}
			
			$from_id_arr = array_unique($from_id_arr);
			
			if(!empty($from_id_arr))
			{
				$select = $this->select();
				$select->from($this->_name, array("group_id"));
				$select->where("from_id IN (?)", $from_id_arr);
				$select->where("status = ?", 1);
				$select->where("expired_date >= ?", date("Y-m-d"));
				$rows = $this->fetchAll($select);
				
				if($rows)
				{
					foreach($rows as $row)
					{
						$result[] = $row['group_id'];
						
						$result = array_unique($result);
					}
				}
			}
		}
		
		return $result;
	}
}